In [1]:
### Predictions from the model
In [2]:
#!tar chvfz notebook.tar.gz *
In [1]:
import torch, detectron2
!nvcc --version
TORCH_VERSION = ".".join(torch.__version__.split(".")[:2])
CUDA_VERSION = torch.__version__.split("+")[-1]
print("torch: ", TORCH_VERSION, "; cuda: ", CUDA_VERSION)
print("detectron2:", detectron2.__version__)
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
torch:  1.9 ; cuda:  cu111
detectron2: 0.6
In [2]:
# Some basic setup:
# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

# import some common libraries
import numpy as np
import os, json, cv2, random
#from google.colab.patches import cv2_imshow

# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog, DatasetCatalog
In [3]:
import json
  
# Opening JSON file
f = open('/root/raghav/labelstudio/result.json')
  
dataset_dicts = json.load(f)
In [4]:
from detectron2.data.datasets import register_coco_instances
register_coco_instances("my_dataset8", {}, "/root/raghav/labelstudio/result.json", "/root/raghav/labelstudio/")
In [8]:
from detectron2.engine import DefaultTrainer

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("my_dataset8",)
cfg.DATASETS.TEST = ()
cfg.DATALOADER.NUM_WORKERS = 2
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml")  # Let training initialize from model zoo
cfg.SOLVER.IMS_PER_BATCH = 2  # This is the real "batch size" commonly known to deep learning people
cfg.SOLVER.BASE_LR = 0.00025  # pick a good LR
cfg.SOLVER.MAX_ITER = 1000    # 300 iterations seems good enough for this toy dataset; you will need to train longer for a practical dataset
cfg.SOLVER.STEPS = []        # do not decay learning rate
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128   # The "RoIHead batch size". 128 is faster, and good enough for this toy dataset (default: 512)
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1  # only has one class (ballon). (see https://detectron2.readthedocs.io/tutorials/datasets.html#update-the-config-for-new-datasets)
# NOTE: this config means the number of classes, but a few popular unofficial tutorials incorrect uses num_classes+1 here.
In [9]:
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
In [10]:
trainer = DefaultTrainer(cfg) 
trainer.resume_or_load(resume=False)
[11/30 20:04:54 d2.engine.defaults]: Model:
GeneralizedRCNN(
  (backbone): FPN(
    (fpn_lateral2): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (fpn_lateral3): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (fpn_lateral4): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (fpn_lateral5): Conv2d(2048, 256, kernel_size=(1, 1), stride=(1, 1))
    (fpn_output5): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (top_block): LastLevelMaxPool()
    (bottom_up): ResNet(
      (stem): BasicStem(
        (conv1): Conv2d(
          3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False
          (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
        )
      )
      (res2): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv1): Conv2d(
            64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv2): Conv2d(
            64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv3): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv2): Conv2d(
            64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv3): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv2): Conv2d(
            64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=64, eps=1e-05)
          )
          (conv3): Conv2d(
            64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
        )
      )
      (res3): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv1): Conv2d(
            256, 128, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
        (3): BottleneckBlock(
          (conv1): Conv2d(
            512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv2): Conv2d(
            128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=128, eps=1e-05)
          )
          (conv3): Conv2d(
            128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
        )
      )
      (res4): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            512, 1024, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
          (conv1): Conv2d(
            512, 256, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (3): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (4): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (5): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (6): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (7): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (8): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (9): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (10): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (11): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (12): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (13): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (14): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (15): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (16): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (17): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (18): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (19): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (20): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (21): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
        (22): BottleneckBlock(
          (conv1): Conv2d(
            1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv2): Conv2d(
            256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=256, eps=1e-05)
          )
          (conv3): Conv2d(
            256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=1024, eps=1e-05)
          )
        )
      )
      (res5): Sequential(
        (0): BottleneckBlock(
          (shortcut): Conv2d(
            1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
          (conv1): Conv2d(
            1024, 512, kernel_size=(1, 1), stride=(2, 2), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv2): Conv2d(
            512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv3): Conv2d(
            512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
        )
        (1): BottleneckBlock(
          (conv1): Conv2d(
            2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv2): Conv2d(
            512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv3): Conv2d(
            512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
        )
        (2): BottleneckBlock(
          (conv1): Conv2d(
            2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv2): Conv2d(
            512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=512, eps=1e-05)
          )
          (conv3): Conv2d(
            512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False
            (norm): FrozenBatchNorm2d(num_features=2048, eps=1e-05)
          )
        )
      )
    )
  )
  (proposal_generator): RPN(
    (rpn_head): StandardRPNHead(
      (conv): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (objectness_logits): Conv2d(256, 3, kernel_size=(1, 1), stride=(1, 1))
      (anchor_deltas): Conv2d(256, 12, kernel_size=(1, 1), stride=(1, 1))
    )
    (anchor_generator): DefaultAnchorGenerator(
      (cell_anchors): BufferList()
    )
  )
  (roi_heads): StandardROIHeads(
    (box_pooler): ROIPooler(
      (level_poolers): ModuleList(
        (0): ROIAlign(output_size=(7, 7), spatial_scale=0.25, sampling_ratio=0, aligned=True)
        (1): ROIAlign(output_size=(7, 7), spatial_scale=0.125, sampling_ratio=0, aligned=True)
        (2): ROIAlign(output_size=(7, 7), spatial_scale=0.0625, sampling_ratio=0, aligned=True)
        (3): ROIAlign(output_size=(7, 7), spatial_scale=0.03125, sampling_ratio=0, aligned=True)
      )
    )
    (box_head): FastRCNNConvFCHead(
      (flatten): Flatten(start_dim=1, end_dim=-1)
      (fc1): Linear(in_features=12544, out_features=1024, bias=True)
      (fc_relu1): ReLU()
      (fc2): Linear(in_features=1024, out_features=1024, bias=True)
      (fc_relu2): ReLU()
    )
    (box_predictor): FastRCNNOutputLayers(
      (cls_score): Linear(in_features=1024, out_features=2, bias=True)
      (bbox_pred): Linear(in_features=1024, out_features=4, bias=True)
    )
    (mask_pooler): ROIPooler(
      (level_poolers): ModuleList(
        (0): ROIAlign(output_size=(14, 14), spatial_scale=0.25, sampling_ratio=0, aligned=True)
        (1): ROIAlign(output_size=(14, 14), spatial_scale=0.125, sampling_ratio=0, aligned=True)
        (2): ROIAlign(output_size=(14, 14), spatial_scale=0.0625, sampling_ratio=0, aligned=True)
        (3): ROIAlign(output_size=(14, 14), spatial_scale=0.03125, sampling_ratio=0, aligned=True)
      )
    )
    (mask_head): MaskRCNNConvUpsampleHead(
      (mask_fcn1): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (mask_fcn2): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (mask_fcn3): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (mask_fcn4): Conv2d(
        256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
        (activation): ReLU()
      )
      (deconv): ConvTranspose2d(256, 256, kernel_size=(2, 2), stride=(2, 2))
      (deconv_relu): ReLU()
      (predictor): Conv2d(256, 1, kernel_size=(1, 1), stride=(1, 1))
    )
  )
)
WARNING [11/30 20:04:54 d2.data.datasets.coco]: 
Category ids in annotations are not in [1, #categories]! We'll apply a mapping for you.

[11/30 20:04:54 d2.data.datasets.coco]: Loaded 75 images in COCO format from /root/raghav/labelstudio/result.json
[11/30 20:04:54 d2.data.build]: Removed 8 images with no usable annotations. 67 images left.
[11/30 20:04:54 d2.data.build]: Distribution of instances among all 1 categories:
|  category  | #instances   |
|:----------:|:-------------|
|    Wire    | 107          |
|            |              |
[11/30 20:04:54 d2.data.dataset_mapper]: [DatasetMapper] Augmentations used in training: [ResizeShortestEdge(short_edge_length=(640, 672, 704, 736, 768, 800), max_size=1333, sample_style='choice'), RandomFlip()]
[11/30 20:04:54 d2.data.build]: Using training sampler TrainingSampler
[11/30 20:04:54 d2.data.common]: Serializing 67 elements to byte tensors and concatenating them all ...
[11/30 20:04:54 d2.data.common]: Serialized dataset takes 0.05 MiB
2022-11-30 20:04:54.950593: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-11-30 20:04:56.227364: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2022-11-30 20:04:58.412989: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /root/anaconda3/lib/python3.9/site-packages/cv2/../../lib64:
2022-11-30 20:04:58.413105: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /root/anaconda3/lib/python3.9/site-packages/cv2/../../lib64:
2022-11-30 20:04:58.413117: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
/root/anaconda3/lib/python3.9/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.0
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
Skip loading parameter 'roi_heads.box_predictor.cls_score.weight' to the model due to incompatible shapes: (81, 1024) in the checkpoint but (2, 1024) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.box_predictor.cls_score.bias' to the model due to incompatible shapes: (81,) in the checkpoint but (2,) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.box_predictor.bbox_pred.weight' to the model due to incompatible shapes: (320, 1024) in the checkpoint but (4, 1024) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.box_predictor.bbox_pred.bias' to the model due to incompatible shapes: (320,) in the checkpoint but (4,) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.mask_head.predictor.weight' to the model due to incompatible shapes: (80, 256, 1, 1) in the checkpoint but (1, 256, 1, 1) in the model! You might want to double check if this is expected.
Skip loading parameter 'roi_heads.mask_head.predictor.bias' to the model due to incompatible shapes: (80,) in the checkpoint but (1,) in the model! You might want to double check if this is expected.
Some model parameters or buffers are not found in the checkpoint:
roi_heads.box_predictor.bbox_pred.{bias, weight}
roi_heads.box_predictor.cls_score.{bias, weight}
roi_heads.mask_head.predictor.{bias, weight}
In [11]:
trainer.train()
[11/30 20:05:10 d2.engine.train_loop]: Starting training from iteration 0
/root/anaconda3/lib/python3.9/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
ERROR [11/30 20:05:16 d2.engine.train_loop]: Exception during training:
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/detectron2/engine/train_loop.py", line 149, in train
    self.run_step()
  File "/root/anaconda3/lib/python3.9/site-packages/detectron2/engine/defaults.py", line 494, in run_step
    self._trainer.run_step()
  File "/root/anaconda3/lib/python3.9/site-packages/detectron2/engine/train_loop.py", line 286, in run_step
    losses.backward()
  File "/root/anaconda3/lib/python3.9/site-packages/torch/_tensor.py", line 255, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
  File "/root/anaconda3/lib/python3.9/site-packages/torch/autograd/__init__.py", line 147, in backward
    Variable._execution_engine.run_backward(
RuntimeError: CUDA out of memory. Tried to allocate 132.00 MiB (GPU 0; 7.44 GiB total capacity; 3.39 GiB already allocated; 63.31 MiB free; 3.66 GiB reserved in total by PyTorch)
[11/30 20:05:16 d2.engine.hooks]: Overall training speed: 3 iterations in 0:00:03 (1.2310 s / it)
[11/30 20:05:16 d2.engine.hooks]: Total training time: 0:00:03 (0:00:00 on hooks)
[11/30 20:05:16 d2.utils.events]:  eta: 0:16:59  iter: 5  total_loss: 1.679  loss_cls: 0.7009  loss_box_reg: 0.06091  loss_mask: 0.6964  loss_rpn_cls: 0.0995  loss_rpn_loc: 0.01016  time: 1.0091  data_time: 0.1645  lr: 1.249e-06  max_mem: 3626M
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [11], in <cell line: 1>()
----> 1 trainer.train()

File ~/anaconda3/lib/python3.9/site-packages/detectron2/engine/defaults.py:484, in DefaultTrainer.train(self)
    477 def train(self):
    478     """
    479     Run training.
    480 
    481     Returns:
    482         OrderedDict of results, if evaluation is enabled. Otherwise None.
    483     """
--> 484     super().train(self.start_iter, self.max_iter)
    485     if len(self.cfg.TEST.EXPECTED_RESULTS) and comm.is_main_process():
    486         assert hasattr(
    487             self, "_last_eval_results"
    488         ), "No evaluation results obtained during training!"

File ~/anaconda3/lib/python3.9/site-packages/detectron2/engine/train_loop.py:149, in TrainerBase.train(self, start_iter, max_iter)
    147 for self.iter in range(start_iter, max_iter):
    148     self.before_step()
--> 149     self.run_step()
    150     self.after_step()
    151 # self.iter == max_iter can be used by `after_train` to
    152 # tell whether the training successfully finished or failed
    153 # due to exceptions.

File ~/anaconda3/lib/python3.9/site-packages/detectron2/engine/defaults.py:494, in DefaultTrainer.run_step(self)
    492 def run_step(self):
    493     self._trainer.iter = self.iter
--> 494     self._trainer.run_step()

File ~/anaconda3/lib/python3.9/site-packages/detectron2/engine/train_loop.py:286, in SimpleTrainer.run_step(self)
    281 """
    282 If you need to accumulate gradients or do something similar, you can
    283 wrap the optimizer with your custom `zero_grad()` method.
    284 """
    285 self.optimizer.zero_grad()
--> 286 losses.backward()
    288 self._write_metrics(loss_dict, data_time)
    290 """
    291 If you need gradient clipping/scaling or other processing, you can
    292 wrap the optimizer with your custom `step()` method. But it is
    293 suboptimal as explained in https://arxiv.org/abs/2006.15704 Sec 3.2.4
    294 """

File ~/anaconda3/lib/python3.9/site-packages/torch/_tensor.py:255, in Tensor.backward(self, gradient, retain_graph, create_graph, inputs)
    246 if has_torch_function_unary(self):
    247     return handle_torch_function(
    248         Tensor.backward,
    249         (self,),
   (...)
    253         create_graph=create_graph,
    254         inputs=inputs)
--> 255 torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)

File ~/anaconda3/lib/python3.9/site-packages/torch/autograd/__init__.py:147, in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
    144 if retain_graph is None:
    145     retain_graph = create_graph
--> 147 Variable._execution_engine.run_backward(
    148     tensors, grad_tensors_, retain_graph, create_graph, inputs,
    149     allow_unreachable=True, accumulate_grad=True)

RuntimeError: CUDA out of memory. Tried to allocate 132.00 MiB (GPU 0; 7.44 GiB total capacity; 3.39 GiB already allocated; 63.31 MiB free; 3.66 GiB reserved in total by PyTorch)
In [ ]:
cfg.OUTPUT_DIR
In [ ]:
from detectron2.utils.visualizer import ColorMode
import matplotlib.pyplot as plt
from skimage.io import imshow, imread
from skimage.color import rgb2hsv, hsv2rgb
In [ ]:
 
In [6]:
cfg.MODEL.DEVICE
Out[6]:
'cuda'
In [7]:
import torch
torch.cuda.is_available()
Out[7]:
True
In [8]:
# Inference should use the config with parameters that are used in training
# cfg now already contains everything we've set previously. We changed it a little bit for inference:
cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth")  # path to the model we just trained
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7   # set a custom testing threshold
predictor = DefaultPredictor(cfg)
[11/30 19:34:51 d2.checkpoint.c2_model_loading]: Following weights matched with model:
| Names in Model                                  | Names in Checkpoint                                                                                  | Shapes                                          |
|:------------------------------------------------|:-----------------------------------------------------------------------------------------------------|:------------------------------------------------|
| backbone.bottom_up.res2.0.conv1.*               | backbone.bottom_up.res2.0.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (64,) (64,) (64,) (64,) (64,64,1,1)             |
| backbone.bottom_up.res2.0.conv2.*               | backbone.bottom_up.res2.0.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (64,) (64,) (64,) (64,) (64,64,3,3)             |
| backbone.bottom_up.res2.0.conv3.*               | backbone.bottom_up.res2.0.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,64,1,1)        |
| backbone.bottom_up.res2.0.shortcut.*            | backbone.bottom_up.res2.0.shortcut.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight} | (256,) (256,) (256,) (256,) (256,64,1,1)        |
| backbone.bottom_up.res2.1.conv1.*               | backbone.bottom_up.res2.1.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (64,) (64,) (64,) (64,) (64,256,1,1)            |
| backbone.bottom_up.res2.1.conv2.*               | backbone.bottom_up.res2.1.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (64,) (64,) (64,) (64,) (64,64,3,3)             |
| backbone.bottom_up.res2.1.conv3.*               | backbone.bottom_up.res2.1.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,64,1,1)        |
| backbone.bottom_up.res2.2.conv1.*               | backbone.bottom_up.res2.2.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (64,) (64,) (64,) (64,) (64,256,1,1)            |
| backbone.bottom_up.res2.2.conv2.*               | backbone.bottom_up.res2.2.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (64,) (64,) (64,) (64,) (64,64,3,3)             |
| backbone.bottom_up.res2.2.conv3.*               | backbone.bottom_up.res2.2.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,64,1,1)        |
| backbone.bottom_up.res3.0.conv1.*               | backbone.bottom_up.res3.0.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,256,1,1)       |
| backbone.bottom_up.res3.0.conv2.*               | backbone.bottom_up.res3.0.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,128,3,3)       |
| backbone.bottom_up.res3.0.conv3.*               | backbone.bottom_up.res3.0.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,128,1,1)       |
| backbone.bottom_up.res3.0.shortcut.*            | backbone.bottom_up.res3.0.shortcut.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight} | (512,) (512,) (512,) (512,) (512,256,1,1)       |
| backbone.bottom_up.res3.1.conv1.*               | backbone.bottom_up.res3.1.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,512,1,1)       |
| backbone.bottom_up.res3.1.conv2.*               | backbone.bottom_up.res3.1.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,128,3,3)       |
| backbone.bottom_up.res3.1.conv3.*               | backbone.bottom_up.res3.1.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,128,1,1)       |
| backbone.bottom_up.res3.2.conv1.*               | backbone.bottom_up.res3.2.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,512,1,1)       |
| backbone.bottom_up.res3.2.conv2.*               | backbone.bottom_up.res3.2.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,128,3,3)       |
| backbone.bottom_up.res3.2.conv3.*               | backbone.bottom_up.res3.2.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,128,1,1)       |
| backbone.bottom_up.res3.3.conv1.*               | backbone.bottom_up.res3.3.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,512,1,1)       |
| backbone.bottom_up.res3.3.conv2.*               | backbone.bottom_up.res3.3.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (128,) (128,) (128,) (128,) (128,128,3,3)       |
| backbone.bottom_up.res3.3.conv3.*               | backbone.bottom_up.res3.3.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,128,1,1)       |
| backbone.bottom_up.res4.0.conv1.*               | backbone.bottom_up.res4.0.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,512,1,1)       |
| backbone.bottom_up.res4.0.conv2.*               | backbone.bottom_up.res4.0.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,256,3,3)       |
| backbone.bottom_up.res4.0.conv3.*               | backbone.bottom_up.res4.0.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (1024,) (1024,) (1024,) (1024,) (1024,256,1,1)  |
| backbone.bottom_up.res4.0.shortcut.*            | backbone.bottom_up.res4.0.shortcut.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight} | (1024,) (1024,) (1024,) (1024,) (1024,512,1,1)  |
| backbone.bottom_up.res4.1.conv1.*               | backbone.bottom_up.res4.1.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,1024,1,1)      |
| backbone.bottom_up.res4.1.conv2.*               | backbone.bottom_up.res4.1.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,256,3,3)       |
| backbone.bottom_up.res4.1.conv3.*               | backbone.bottom_up.res4.1.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (1024,) (1024,) (1024,) (1024,) (1024,256,1,1)  |
| backbone.bottom_up.res4.2.conv1.*               | backbone.bottom_up.res4.2.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,1024,1,1)      |
| backbone.bottom_up.res4.2.conv2.*               | backbone.bottom_up.res4.2.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,256,3,3)       |
| backbone.bottom_up.res4.2.conv3.*               | backbone.bottom_up.res4.2.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (1024,) (1024,) (1024,) (1024,) (1024,256,1,1)  |
| backbone.bottom_up.res4.3.conv1.*               | backbone.bottom_up.res4.3.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,1024,1,1)      |
| backbone.bottom_up.res4.3.conv2.*               | backbone.bottom_up.res4.3.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,256,3,3)       |
| backbone.bottom_up.res4.3.conv3.*               | backbone.bottom_up.res4.3.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (1024,) (1024,) (1024,) (1024,) (1024,256,1,1)  |
| backbone.bottom_up.res4.4.conv1.*               | backbone.bottom_up.res4.4.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,1024,1,1)      |
| backbone.bottom_up.res4.4.conv2.*               | backbone.bottom_up.res4.4.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,256,3,3)       |
| backbone.bottom_up.res4.4.conv3.*               | backbone.bottom_up.res4.4.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (1024,) (1024,) (1024,) (1024,) (1024,256,1,1)  |
| backbone.bottom_up.res4.5.conv1.*               | backbone.bottom_up.res4.5.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,1024,1,1)      |
| backbone.bottom_up.res4.5.conv2.*               | backbone.bottom_up.res4.5.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (256,) (256,) (256,) (256,) (256,256,3,3)       |
| backbone.bottom_up.res4.5.conv3.*               | backbone.bottom_up.res4.5.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (1024,) (1024,) (1024,) (1024,) (1024,256,1,1)  |
| backbone.bottom_up.res5.0.conv1.*               | backbone.bottom_up.res5.0.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,1024,1,1)      |
| backbone.bottom_up.res5.0.conv2.*               | backbone.bottom_up.res5.0.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,512,3,3)       |
| backbone.bottom_up.res5.0.conv3.*               | backbone.bottom_up.res5.0.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (2048,) (2048,) (2048,) (2048,) (2048,512,1,1)  |
| backbone.bottom_up.res5.0.shortcut.*            | backbone.bottom_up.res5.0.shortcut.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight} | (2048,) (2048,) (2048,) (2048,) (2048,1024,1,1) |
| backbone.bottom_up.res5.1.conv1.*               | backbone.bottom_up.res5.1.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,2048,1,1)      |
| backbone.bottom_up.res5.1.conv2.*               | backbone.bottom_up.res5.1.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,512,3,3)       |
| backbone.bottom_up.res5.1.conv3.*               | backbone.bottom_up.res5.1.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (2048,) (2048,) (2048,) (2048,) (2048,512,1,1)  |
| backbone.bottom_up.res5.2.conv1.*               | backbone.bottom_up.res5.2.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,2048,1,1)      |
| backbone.bottom_up.res5.2.conv2.*               | backbone.bottom_up.res5.2.conv2.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (512,) (512,) (512,) (512,) (512,512,3,3)       |
| backbone.bottom_up.res5.2.conv3.*               | backbone.bottom_up.res5.2.conv3.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}    | (2048,) (2048,) (2048,) (2048,) (2048,512,1,1)  |
| backbone.bottom_up.stem.conv1.*                 | backbone.bottom_up.stem.conv1.{norm.bias,norm.running_mean,norm.running_var,norm.weight,weight}      | (64,) (64,) (64,) (64,) (64,3,7,7)              |
| backbone.fpn_lateral2.*                         | backbone.fpn_lateral2.{bias,weight}                                                                  | (256,) (256,256,1,1)                            |
| backbone.fpn_lateral3.*                         | backbone.fpn_lateral3.{bias,weight}                                                                  | (256,) (256,512,1,1)                            |
| backbone.fpn_lateral4.*                         | backbone.fpn_lateral4.{bias,weight}                                                                  | (256,) (256,1024,1,1)                           |
| backbone.fpn_lateral5.*                         | backbone.fpn_lateral5.{bias,weight}                                                                  | (256,) (256,2048,1,1)                           |
| backbone.fpn_output2.*                          | backbone.fpn_output2.{bias,weight}                                                                   | (256,) (256,256,3,3)                            |
| backbone.fpn_output3.*                          | backbone.fpn_output3.{bias,weight}                                                                   | (256,) (256,256,3,3)                            |
| backbone.fpn_output4.*                          | backbone.fpn_output4.{bias,weight}                                                                   | (256,) (256,256,3,3)                            |
| backbone.fpn_output5.*                          | backbone.fpn_output5.{bias,weight}                                                                   | (256,) (256,256,3,3)                            |
| proposal_generator.rpn_head.anchor_deltas.*     | proposal_generator.rpn_head.anchor_deltas.{bias,weight}                                              | (12,) (12,256,1,1)                              |
| proposal_generator.rpn_head.conv.*              | proposal_generator.rpn_head.conv.{bias,weight}                                                       | (256,) (256,256,3,3)                            |
| proposal_generator.rpn_head.objectness_logits.* | proposal_generator.rpn_head.objectness_logits.{bias,weight}                                          | (3,) (3,256,1,1)                                |
| roi_heads.box_head.fc1.*                        | roi_heads.box_head.fc1.{bias,weight}                                                                 | (1024,) (1024,12544)                            |
| roi_heads.box_head.fc2.*                        | roi_heads.box_head.fc2.{bias,weight}                                                                 | (1024,) (1024,1024)                             |
| roi_heads.box_predictor.bbox_pred.*             | roi_heads.box_predictor.bbox_pred.{bias,weight}                                                      | (4,) (4,1024)                                   |
| roi_heads.box_predictor.cls_score.*             | roi_heads.box_predictor.cls_score.{bias,weight}                                                      | (2,) (2,1024)                                   |
| roi_heads.mask_head.deconv.*                    | roi_heads.mask_head.deconv.{bias,weight}                                                             | (256,) (256,256,2,2)                            |
| roi_heads.mask_head.mask_fcn1.*                 | roi_heads.mask_head.mask_fcn1.{bias,weight}                                                          | (256,) (256,256,3,3)                            |
| roi_heads.mask_head.mask_fcn2.*                 | roi_heads.mask_head.mask_fcn2.{bias,weight}                                                          | (256,) (256,256,3,3)                            |
| roi_heads.mask_head.mask_fcn3.*                 | roi_heads.mask_head.mask_fcn3.{bias,weight}                                                          | (256,) (256,256,3,3)                            |
| roi_heads.mask_head.mask_fcn4.*                 | roi_heads.mask_head.mask_fcn4.{bias,weight}                                                          | (256,) (256,256,3,3)                            |
| roi_heads.mask_head.predictor.*                 | roi_heads.mask_head.predictor.{bias,weight}                                                          | (1,) (1,256,1,1)                                |
In [9]:
from detectron2.utils.visualizer import ColorMode
In [10]:
import matplotlib.pyplot as plt

from skimage.io import imshow, imread
from skimage.color import rgb2hsv, hsv2rgb
/root/anaconda3/lib/python3.9/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.0
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
In [11]:
import json
  
# Opening JSON file
f = open('/root/labelstudio/result.json')
  
dataset_dicts = json.load(f)

dataset_dicts.keys()
Out[11]:
dict_keys(['images', 'categories', 'annotations', 'info'])
In [12]:
def get_box(im):
    outputs = predictor(im)
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
    x1 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][0]
    y1 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][1]
    x2 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][2]
    y2 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][3]
    #imshow(im[int(y1):int(y2),int(x1):int(x2),:])
    return im[int(y1):int(y2),int(x1):int(x2),:]
In [13]:
def mask_to_rect(mask):
    nmpy_mask = np.array(mask)
    nmpy_mask = nmpy_mask.reshape(nmpy_mask.shape[1],nmpy_mask.shape[2])
    coordinates = np.argwhere(nmpy_mask)
    rect = cv2.minAreaRect(coordinates) # basically you can feed this rect into your classifier
    (x,y),(w,h), a = rect 
    #print(rect)
    return min(w,h)
    
In [14]:
%%time
#-- 5-10 seconds ## Loading to prediction to output

im = imread("/root/labelstudio/images/"+dataset_dicts['images'][1]['file_name'])
imshow(get_box(im))
/root/anaconda3/lib/python3.9/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
CPU times: user 1.25 s, sys: 623 ms, total: 1.87 s
Wall time: 1.16 s
Out[14]:
<matplotlib.image.AxesImage at 0x7f03c744d190>
In [15]:
# def mask_to_rect(mask):
#     coordinates = np.argwhere(mask)
#     rect = cv2.minAreaRect(coordinates) # basically you can feed this rect into your classifier
#     (x,y),(w,h), a = rect 
#     #print(rect)
#     return min(w,h)
    
In [16]:
# mask = predictor(im)['instances'].pred_masks.tolist()
# mask_to_rect(mask)
In [17]:
# rect = cv2.minAreaRect(coordinates) # basically you can feed this rect into your classifier
# (x,y),(w,h), a = rect # a - angle

# box = cv2.boxPoints(rect)
# box = np.int0(box) #turn into ints
# rect2 = cv2.drawContours(im.copy(),[box[:,-1::-1]],0,(0,0,255),10)

# plt.imshow(rect2)
# plt.show()
In [ ]:
 
In [18]:
def get_region(im):
    outputs = predictor(im)
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
    mask = outputs['instances'].pred_masks.tolist()
    bndl_width = mask_to_rect(mask)    
    bundle_area = np.array(mask).reshape(im.shape[0],im.shape[1],1).sum()
    mask = np.array(mask).reshape(im.shape[0],im.shape[1],1)*im
    x1 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][0] 
    y1 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][1]
    x2 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][2]
    y2 = outputs['instances'].pred_boxes.tensor.tolist()[max_index][3]
    #imshow(mask[int(y1):int(y2),int(x1):int(x2),:])
    print(y2,y1,x2,x1,(y2-y1)*(x2-x1))
    return mask[int(y1):int(y2),int(x1):int(x2),:], bundle_area, bndl_width
In [19]:
im1 = get_region(im)
2511.053955078125 2168.43701171875 1346.9364013671875 1029.177001953125 108869.75415095687
In [20]:
imshow(im1[0])
Out[20]:
<matplotlib.image.AxesImage at 0x7f03c738a220>
In [ ]:
 
In [21]:
imshow(np.array(predictor(im)['instances'].pred_masks.tolist()).reshape(im.shape[0],im.shape[1])*255)
/root/anaconda3/lib/python3.9/site-packages/skimage/io/_plugins/matplotlib_plugin.py:150: UserWarning: Low image data range; displaying image with stretched contrast.
  lo, hi, cmap = _get_display_range(image)
Out[21]:
<matplotlib.image.AxesImage at 0x7f03c6fc6dc0>
In [22]:
## Post Processing
In [23]:
def light_level(img,thres = 60):
    r,g,b,_ = cv2.mean(img)
    gray = 0.2989 * r + 0.5870 * g + 0.1140 * b
    if gray <= 60:
        return "dark"
    else :
        return "okay light"

def change_brightness(img, value=60):
    hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    h, s, v = cv2.split(hsv)
    v = cv2.add(v,value)
    v[v > 255] = 255
    v[v < 0] = 0
    final_hsv = cv2.merge((h, s, v))
    img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2RGB)
    return img



def variance_of_laplacian(image):
    # compute the Laplacian of the image and then return the focus
    # measure, which is simply the variance of the Laplacian
    return cv2.Laplacian(image, cv2.CV_64F).var()

def is_blurry(image, threshold = 80):
    
    gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
    fm = variance_of_laplacian(gray)
    text = "Not Blurry"
    # if the focus measure is less than the supplied threshold,
    # then the image should be considered "blurry"
    if fm < threshold:
        text = "Blurry"
    return [text, round(fm,2)]
In [24]:
im1 = get_box(im)
mask_im,bundle_area,bndl_width = get_region(im)
2511.053955078125 2168.43701171875 1346.9364013671875 1029.177001953125 108869.75415095687
In [25]:
original = im1.copy()
image = cv2.cvtColor(im1, cv2.COLOR_RGB2HSV)
lower = np.array([20, 60, 60], dtype="uint8")
upper = np.array([30, 255, 255], dtype="uint8")
mask = cv2.inRange(image, lower, upper)
cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
In [26]:
# points = []
# for i in cnts[58]:
#     points.append([i[0][0],i[0][1]])
# points = torch.tensor(points)
# #points
In [ ]:
 
In [27]:
# points = torch.tensor(points)
In [28]:
import torch
import numpy as np
import matplotlib.pyplot as plt

import cv2

import matplotlib.pyplot as plt

def plot_graph(X,Y, slopes,constants):
    plt.plot(X,Y,"go")
    #plt.xlim(0,500)
    #plt.ylim(0,500)
    plt.xlim(int(X.min()-20), int(X.max()+20))
    plt.ylim(int(Y.min()-20), int(Y.max()+20))

    def abline(slope, intercept):
        axes = plt.gca()
        x_vals = np.array(axes.get_xlim())
        y_vals = intercept + slope * x_vals
        plt.plot(x_vals, y_vals, '--')

    abline(float(slopes[0]),float(constants[0]))
    abline(float(slopes[0]),float(constants[2]))
    abline(float(slopes[1]),float(constants[1]))
    abline(float(slopes[1]),float(constants[3]))  
    plt.show()

def is_between(slopes,constants,points):
    Y = points[:,1]
    X = points[:,0]
    a = torch.cat((Y - slopes*X, Y - slopes*X), 0) - constants
    check = (a[0]*a[2]<=0)*(a[1]*a[3]<=0)
    between = torch.sum(check)
    total = check.size(dim=0)
    ratio = between/total
    return ratio

#points = torch.tensor([[0,2],[2,0],[0.5,1.5],[1,1],[2,2],[3,3],[3,0.8],[2.5,3.5],[2,4],[3,1.5],[0,2.3],[1.5,3],[1,3]])

def get_rect(cnt):
    
    points = []
    
    for i in cnt:
        points.append([i[0][0],i[0][1]])
    points = torch.tensor(points)

    Y = points[:,1]
    X = points[:,0]
    
    learning_rate = 0.01

    epochs = 1000
    n = X.shape[0]

    import cv2
    import numpy as np
    

    rect = cv2.minAreaRect(np.array(points))
    m = np.tan(np.pi*rect[2]/180)
    slope = torch.tensor([[m]],requires_grad=True)
    box = cv2.boxPoints(rect)

    c0 = box[0][1] - (m*box[0][0])
    c1 = box[0][1] + (box[0][0]/m)
    c2 = box[2][1] - (m* box[2][0])
    c3 = box[2][1] + (box[2][0]/m)

    constants = torch.tensor([[c0],[c1],[c2],[c3]],requires_grad=True)
    # slope = torch.rand([1,1],requires_grad=True)
    # constants = torch.rand([4,1],requires_grad=True)
    
    #print(slope,constants)
    for i in range(epochs):

        slopes = torch.cat((slope,-1/slope) ,0)
        num  = abs(torch.cat((Y - slopes*X, Y - slopes*X), 0) - constants)
        den = torch.cat((torch.sqrt(1 + slopes*slopes), torch.sqrt(1 + slopes*slopes)), 0)
        distances = num/den
        dists_min = torch.amin(distances,0).sum()/n
        dists_min.backward()

#         if i % 1000 == 0:
#             print(i) 

#         if i%1000==0:
#             plot_graph(X,Y, slopes,constants)

        with torch.no_grad():
            slope -= learning_rate * slope.grad
            constants -= learning_rate *10* constants.grad

            slope.grad.zero_()
            constants.grad.zero_()
            
    #plot_graph(X,Y, slopes,constants)
    dist =  is_between(slopes,constants,points)
    
    if dist >=0.5:
        return(float(abs(constants[0]-constants[2])/torch.sqrt(1+slopes[0]**2)), float(abs(constants[1]-constants[3])/torch.sqrt(1+slopes[1]**2)))
    else :
        return rect[1]
In [29]:
True*False
Out[29]:
0
In [30]:
from sklearn.linear_model import LinearRegression
def count_yellow_wires(im1,blur,bundle_area,bndl_width,area_threshold,erosion_dialation):
    
    original = im1.copy()
    image = cv2.cvtColor(im1, cv2.COLOR_RGB2HSV)
    lower = np.array([20, 60, 60], dtype="uint8")
    upper = np.array([30, 255, 255], dtype="uint8")
    mask = cv2.inRange(image, lower, upper)
    
    
    if erosion_dialation:
        kernel = np.ones((5, 5), np.uint8)
        mask = cv2.erode(mask, kernel, iterations=1)
        mask = cv2.dilate(mask, kernel, iterations=1)

    
    cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if len(cnts) == 2 else cnts[1]
    
    
#      def fit_line(c):
#         [vx,vy,x,y] = cv2.fitLine(c, cv.DIST_L2,0,0.01,0.01)
#         m = vy/vx
#         c = y - (m*x)
#         return (m,c,(c[:,:,0].mean(),c[:,:,1].mean()))
       
    def fit_line(c):
    
        model = LinearRegression()
        model.fit(c[:,:,0],[a[0] for a  in c[:,:,1]])
        return [model.coef_[0],model.intercept_,(c[:,:,0].mean(),c[:,:,1].mean())]
    
    def get_dist(line1, line2):
        m_avg = (line1[0]+line2[0])/2
        y2 = line2[2][1]
        y1 = line1[2][1]
        x2 = line2[2][0]
        x1 = line1[2][0]

        c2 = y2 - m_avg*x2
        c1 = y1 - m_avg*x1

        return (abs(c2 - c1)/np.sqrt(1 + m_avg**2))
    
    def is_same_line(line1, line2,ang_thres = 6, dist_thres = 10):
    
        if abs(np.rad2deg(line1[0]) - np.rad2deg(line2[0])) < ang_thres:
            if get_dist(line1, line2) < dist_thres:
                return True
        return False
    
    canvas = np.zeros(image.shape,np.uint8)
    canvas.fill(255)
    num_cnts =0
    ctr_lines = []
    for a,c in enumerate(cnts):
        
        ratio = cv2.contourArea(c)/bundle_area 
        if ratio >= area_threshold:
            line = fit_line(c)
            #print(get_rect(c),bndl_width/7)
            if min(get_rect(c)) >= bndl_width/5:
                line = line +[1]
            else:
                line = line + [0]
            num_cnts +=1
            #print(f"num_cnts = {num_cnts}")
            cv2.drawContours(canvas, cnts, a,(0,255,0),2)
            ctr_lines.append(line)
        #if ratio!=0:
            #print(bundle_area,cv2.contourArea(c),ratio)
            

    def count_wires(ctr_lines,ang_thres = 6, dist_thres = 10):
        print(ctr_lines)
        grp_dict = {} 
        for i in ctr_lines:

            for j in grp_dict.keys():
                if is_same_line(i,j,ang_thres, dist_thres):
                    #grp_dict[j] = 
                    grp_dict[tuple(j)].append(tuple(i))
                    #print(f"found {i}:{j}")
                    #print(grp_dict)
                    break


            else :
                grp_dict[tuple(i)] = [tuple(i)]
        #print(grp_dict)
        print(grp_dict)
        num = 0
        for i,j in grp_dict.items():
            check = True
            if i[3] == 1:
                num += 2
                break
            else:
                for m in j:
                    if m[3] == 1:
                        num += 2
                        check = False
                        break
            if check:
                num += 1
          
        return num

    no_wires = count_wires(ctr_lines,15,25)
    
    fig, ax = plt.subplots(1,3, figsize = (12,5))

    ax[0].imshow(im1)
    ax[1].imshow(mask)
    ax[2].imshow(canvas)

    ax[0].set_title(f"original image {blur}")
    ax[1].set_title(f"masked Image - contours : {num_cnts}")
    ax[2].set_title(f"original image wires - {no_wires}")
    
    
    fig.show()
    
    return no_wires
In [31]:
def post_processing(image,mask_img,bundle_area,bndl_width,area_threshold,erosion_dialation,header_blur):
    
    light_lvl = light_level(image)
    #blur = is_blurry(image) + [light_lvl]
    blur = header_blur
    
    if light_lvl == "dark":
        return count_yellow_wires(change_brightness(mask_img),blur,bundle_area,bndl_width,area_threshold,erosion_dialation)
    else :
        return count_yellow_wires(mask_img,blur,bundle_area,bndl_width,area_threshold,erosion_dialation)
In [32]:
im = imread("/root/labelstudio/images/"+dataset_dicts['images'][0]['file_name'])
In [33]:
image = get_box(im)
mask_img,bundle_area,bndl_width = get_region(im)
        
2561.950439453125 2327.163330078125 1195.7205810546875 904.9489135742188 68269.43929588795
In [34]:
imshow(mask_img)
Out[34]:
<matplotlib.image.AxesImage at 0x7f03c6f7dca0>
In [ ]:
 
In [35]:
mask_img.shape
Out[35]:
(234, 291, 3)
In [36]:
cv2.mean(im)
Out[36]:
(112.19787295222872, 107.25415459393633, 104.0104923672787, 0.0)
In [37]:
#!pip install flask_restful
In [38]:
from flask import Flask,request
from flask_restful import Resource, Api, reqparse
import pandas as pd
import ast
app = Flask(__name__)
api = Api(app)
In [39]:
import os
os.getcwd()
Out[39]:
'/root/Puneet/Puneetbackup'
In [40]:
import PIL
In [41]:
import cv2

class Users(Resource):
    
    def post(self):
        r = request
        blur = request.headers['blur']
        # convert string of image data to uint8
        nparr = np.fromstring(r.data, np.uint8)
        # decode image
        im = cv2.imdecode(nparr, cv2.IMREAD_COLOR)[:,:,::-1]
        image = get_box(im)
        mask_im,bundle_area,bndl_width = get_region(im)
        no_wires = post_processing(image,mask_im,bundle_area,bndl_width,area_threshold=0.01,erosion_dialation= False,header_blur=blur)
        print(no_wires)
        return {"no_wires":no_wires},200
api.add_resource(Users, '/users')  # '/users' is our entry point for Users
In [42]:
if __name__ == '__main__':
    app.run(port=5002)  # run our Flask app
 * Serving Flask app "__main__" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5002/ (Press CTRL+C to quit)
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
1694.759521484375 1308.13818359375 1533.40625 790.44775390625 287243.6077569723
127.0.0.1 - - [30/Nov/2022 19:35:23] "POST /users HTTP/1.1" 200 -
[[-0.0007116852573731179, 226.34484074553612, (301.5833333333333, 226.13020833333334), 0]]
{(-0.0007116852573731179, 226.34484074553612, (301.5833333333333, 226.13020833333334), 0): [(-0.0007116852573731179, 226.34484074553612, (301.5833333333333, 226.13020833333334), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:35:24,099] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:35:24] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
3018.275146484375 2646.1005859375 1042.877685546875 687.107421875 132408.64153772593
127.0.0.1 - - [30/Nov/2022 19:35:27] "POST /users HTTP/1.1" 200 -
[[-0.0065836484832853485, 167.04284457923887, (217.03490759753595, 165.61396303901438), 0]]
{(-0.0065836484832853485, 167.04284457923887, (217.03490759753595, 165.61396303901438), 0): [(-0.0065836484832853485, 167.04284457923887, (217.03490759753595, 165.61396303901438), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:35:28,718] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:35:28] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:35:29,611] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:35:29] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:35:33] "POST /users HTTP/1.1" 200 -
2122.1728515625 1782.9661865234375 1622.5040283203125 932.4517211914062 234070.34180370718
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
846.8704223632812 737.6737060546875 443.1400146484375 269.0602722167969 19008.93624938093
127.0.0.1 - - [30/Nov/2022 19:35:35] "POST /users HTTP/1.1" 200 -
[[0.0947412202972983, 101.77552533545517, (22.36842105263158, 103.89473684210526), 0], [-0.010164322910084568, 71.29443375653327, (117.15243902439025, 70.10365853658537), 1]]
{(0.0947412202972983, 101.77552533545517, (22.36842105263158, 103.89473684210526), 0): [(0.0947412202972983, 101.77552533545517, (22.36842105263158, 103.89473684210526), 0)], (-0.010164322910084568, 71.29443375653327, (117.15243902439025, 70.10365853658537), 1): [(-0.010164322910084568, 71.29443375653327, (117.15243902439025, 70.10365853658537), 1)]}
3
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2269.623046875 1801.1494140625 1202.814697265625 712.4342651367188 229730.3024995923
127.0.0.1 - - [30/Nov/2022 19:35:39] "POST /users HTTP/1.1" 200 -
[[-0.005413751664055958, 281.92739768033033, (138.2443181818182, 281.17897727272725), 0], [-106227.71789862875, 40539306.48795056, (381.625, 153.64488636363637), 0]]
{(-0.005413751664055958, 281.92739768033033, (138.2443181818182, 281.17897727272725), 0): [(-0.005413751664055958, 281.92739768033033, (138.2443181818182, 281.17897727272725), 0)], (-106227.71789862875, 40539306.48795056, (381.625, 153.64488636363637), 0): [(-106227.71789862875, 40539306.48795056, (381.625, 153.64488636363637), 0)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:35:40,759] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:35:40] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
1636.0025634765625 1123.701904296875 962.1488037109375 431.3564453125 271925.27509506047
127.0.0.1 - - [30/Nov/2022 19:35:43] "POST /users HTTP/1.1" 200 -
[[-0.08958093587123298, 303.33230625607183, (280.6171039844509, 278.1943634596696), 1]]
{(-0.08958093587123298, 303.33230625607183, (280.6171039844509, 278.1943634596696), 1): [(-0.08958093587123298, 303.33230625607183, (280.6171039844509, 278.1943634596696), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:35:46,627] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 13, in post
    mask_im,bundle_area,bndl_width = get_region(im)
  File "/tmp/ipykernel_8512/1858503581.py", line 5, in get_region
    bndl_width = mask_to_rect(mask)
  File "/tmp/ipykernel_8512/1136117754.py", line 3, in mask_to_rect
    nmpy_mask = nmpy_mask.reshape(nmpy_mask.shape[1],nmpy_mask.shape[2])
ValueError: cannot reshape array of size 24385536 into shape (4032,3024)
127.0.0.1 - - [30/Nov/2022 19:35:46] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
662.7681274414062 547.8270263671875 505.9256286621094 295.4608154296875 24191.057370314375
127.0.0.1 - - [30/Nov/2022 19:35:48] "POST /users HTTP/1.1" 200 -
[[-0.0043317436730430725, 75.97179250369561, (125.94535519125684, 75.42622950819673), 1]]
{(-0.0043317436730430725, 75.97179250369561, (125.94535519125684, 75.42622950819673), 1): [(-0.0043317436730430725, 75.97179250369561, (125.94535519125684, 75.42622950819673), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
497.0982666015625 255.20230102539062 493.3269348144531 158.47015380859375 81000.50437114108
127.0.0.1 - - [30/Nov/2022 19:35:49] "POST /users HTTP/1.1" 200 -
[[-0.008340911811288742, 142.46711816469553, (130.10495626822157, 141.38192419825072), 1]]
{(-0.008340911811288742, 142.46711816469553, (130.10495626822157, 141.38192419825072), 1): [(-0.008340911811288742, 142.46711816469553, (130.10495626822157, 141.38192419825072), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:36:10] "POST /users HTTP/1.1" 200 -
5443.71728515625 5116.203125 3335.689697265625 2759.0419921875 188860.28883469105
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2283.63623046875 2018.3516845703125 1091.02734375 670.7355346679688 111496.92171715945
127.0.0.1 - - [30/Nov/2022 19:36:14] "POST /users HTTP/1.1" 200 -
[[-0.006562366579508497, 156.22915194867613, (284.3630573248408, 154.36305732484075), 0]]
{(-0.006562366579508497, 156.22915194867613, (284.3630573248408, 154.36305732484075), 0): [(-0.006562366579508497, 156.22915194867613, (284.3630573248408, 154.36305732484075), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:36:15,768] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:36:15] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:36:16] "POST /users HTTP/1.1" 200 -
258.3098449707031 25.078100204467773 292.5807189941406 50.433799743652344 56476.348466560084
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
1911.3204345703125 1537.8621826171875 1609.8199462890625 937.877685546875 250942.38211020827
127.0.0.1 - - [30/Nov/2022 19:36:21] "POST /users HTTP/1.1" 200 -
[[-76.68956267812517, 16812.223685029792, (216.35177865612647, 220.300395256917), 0], [0.060413934537325964, 81.90965246075157, (412.0927536231884, 106.80579710144927), 0]]
{(-76.68956267812517, 16812.223685029792, (216.35177865612647, 220.300395256917), 0): [(-76.68956267812517, 16812.223685029792, (216.35177865612647, 220.300395256917), 0)], (0.060413934537325964, 81.90965246075157, (412.0927536231884, 106.80579710144927), 0): [(0.060413934537325964, 81.90965246075157, (412.0927536231884, 106.80579710144927), 0)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2872.890869140625 2568.54638671875 1143.7501220703125 589.85986328125 168573.44412967563
127.0.0.1 - - [30/Nov/2022 19:36:27] "POST /users HTTP/1.1" 200 -
[[-0.0005928154114902709, 135.68613748132063, (175.01420454545453, 135.58238636363637), 0], [-23111.885160615446, 7816768.46025621, (338.2124542124542, 41.05860805860806), 0]]
{(-0.0005928154114902709, 135.68613748132063, (175.01420454545453, 135.58238636363637), 0): [(-0.0005928154114902709, 135.68613748132063, (175.01420454545453, 135.58238636363637), 0)], (-23111.885160615446, 7816768.46025621, (338.2124542124542, 41.05860805860806), 0): [(-23111.885160615446, 7816768.46025621, (338.2124542124542, 41.05860805860806), 0)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
1591.424560546875 1230.1871337890625 1385.0545654296875 989.4509887695312 142906.81804890186
127.0.0.1 - - [30/Nov/2022 19:36:32] "POST /users HTTP/1.1" 200 -
[[-551895.0589425993, 126233113.66235328, (228.72625698324023, 222.5828677839851), 1]]
{(-551895.0589425993, 126233113.66235328, (228.72625698324023, 222.5828677839851), 1): [(-551895.0589425993, 126233113.66235328, (228.72625698324023, 222.5828677839851), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:36:33,329] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:36:33] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
707.2477416992188 619.2704467773438 651.5797729492188 433.8108825683594 19158.717893846333
127.0.0.1 - - [30/Nov/2022 19:36:34] "POST /users HTTP/1.1" 200 -
[[-0.006649527017340164, 47.78492638579292, (52.35632183908046, 47.4367816091954), 0]]
{(-0.006649527017340164, 47.78492638579292, (52.35632183908046, 47.4367816091954), 0): [(-0.006649527017340164, 47.78492638579292, (52.35632183908046, 47.4367816091954), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:36:34,979] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 12, in post
    image = get_box(im)
  File "/tmp/ipykernel_8512/4104369290.py", line 3, in get_box
    max_index = outputs['instances'].scores.tolist().index(max(outputs['instances'].scores.tolist()))
ValueError: max() arg is an empty sequence
127.0.0.1 - - [30/Nov/2022 19:36:34] "POST /users HTTP/1.1" 500 -
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
920.86328125 735.456787109375 395.8144226074219 224.341064453125 31792.274173907936
127.0.0.1 - - [30/Nov/2022 19:36:36] "POST /users HTTP/1.1" 200 -
[[-0.007688308652569639, 155.22099506733412, (100.50574712643679, 154.44827586206895), 0], [-35478.83849667076, 3034750.783064751, (85.53398058252426, 104.5), 1]]
{(-0.007688308652569639, 155.22099506733412, (100.50574712643679, 154.44827586206895), 0): [(-0.007688308652569639, 155.22099506733412, (100.50574712643679, 154.44827586206895), 0)], (-35478.83849667076, 3034750.783064751, (85.53398058252426, 104.5), 1): [(-35478.83849667076, 3034750.783064751, (85.53398058252426, 104.5), 1)]}
3
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2277.909912109375 1942.2371826171875 854.6712646484375 470.8945007324219 128823.39385936782
127.0.0.1 - - [30/Nov/2022 19:36:41] "POST /users HTTP/1.1" 200 -
[[-0.007628564751557489, 261.58500676547743, (56.51923076923077, 261.15384615384613), 0], [-19313.965632384854, 3662867.8102634465, (189.63841807909606, 197.92090395480227), 0], [-0.12458502040356134, 155.05549683762985, (305.6390977443609, 116.97744360902256), 0], [-27663.66567621358, 8924130.790985826, (322.5911602209945, 76.78453038674033), 1]]
{(-0.007628564751557489, 261.58500676547743, (56.51923076923077, 261.15384615384613), 0): [(-0.007628564751557489, 261.58500676547743, (56.51923076923077, 261.15384615384613), 0)], (-19313.965632384854, 3662867.8102634465, (189.63841807909606, 197.92090395480227), 0): [(-19313.965632384854, 3662867.8102634465, (189.63841807909606, 197.92090395480227), 0)], (-0.12458502040356134, 155.05549683762985, (305.6390977443609, 116.97744360902256), 0): [(-0.12458502040356134, 155.05549683762985, (305.6390977443609, 116.97744360902256), 0)], (-27663.66567621358, 8924130.790985826, (322.5911602209945, 76.78453038674033), 1): [(-27663.66567621358, 8924130.790985826, (322.5911602209945, 76.78453038674033), 1)]}
5
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2561.8525390625 2327.093017578125 1195.70361328125 905.1984252929688 68198.85892085731
127.0.0.1 - - [30/Nov/2022 19:36:46] "POST /users HTTP/1.1" 200 -
[[-0.0035239800104107364, 40.44958325438359, (160.7289719626168, 39.88317757009346), 0]]
{(-0.0035239800104107364, 40.44958325438359, (160.7289719626168, 39.88317757009346), 0): [(-0.0035239800104107364, 40.44958325438359, (160.7289719626168, 39.88317757009346), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:36:51] "POST /users HTTP/1.1" 200 -
2511.09814453125 2168.314208984375 1346.9593505859375 1029.1146240234375 108952.06626391411
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:36:55] "POST /users HTTP/1.1" 200 -
2180.5234375 1748.447021484375 1125.796142578125 707.2911987304688 180826.1162225157
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:37:00,060] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 14, in post
    no_wires = post_processing(image,mask_im,bundle_area,bndl_width,area_threshold=0.01,erosion_dialation= False,header_blur=blur)
  File "/tmp/ipykernel_8512/3941675305.py", line 10, in post_processing
    return count_yellow_wires(mask_img,blur,bundle_area,bndl_width,area_threshold,erosion_dialation)
  File "/tmp/ipykernel_8512/1990652061.py", line 60, in count_yellow_wires
    line = fit_line(c)
  File "/tmp/ipykernel_8512/1990652061.py", line 30, in fit_line
    model.fit(c[:,:,0],[a[0] for a  in c[:,:,1]])
  File "/root/anaconda3/lib/python3.9/site-packages/sklearn/linear_model/_base.py", line 718, in fit
    self.coef_, self._residues, self.rank_, self.singular_ = linalg.lstsq(X, y)
  File "/root/anaconda3/lib/python3.9/site-packages/scipy/linalg/basic.py", line 1214, in lstsq
    raise ValueError('illegal value in %d-th argument of internal %s'
ValueError: illegal value in 4-th argument of internal None
127.0.0.1 - - [30/Nov/2022 19:37:00] "POST /users HTTP/1.1" 500 -
2463.120361328125 2219.452392578125 853.1563110351562 701.8248291015625 36874.63481068611

Intel MKL ERROR: Parameter 4 was incorrect on entry to DLASCL.
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
/tmp/ipykernel_8512/1990652061.py:111: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).
  fig, ax = plt.subplots(1,3, figsize = (12,5))
127.0.0.1 - - [30/Nov/2022 19:37:04] "POST /users HTTP/1.1" 200 -
2336.400390625 2053.779541015625 1381.9427490234375 1043.43408203125 95669.60706546903
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2466.084228515625 2174.674072265625 1275.044677734375 955.1076049804688 93232.91236138344
127.0.0.1 - - [30/Nov/2022 19:37:09] "POST /users HTTP/1.1" 200 -
[[-170168.99688360593, 38132261.84792239, (224.08370044052865, 163.3259911894273), 0]]
{(-170168.99688360593, 38132261.84792239, (224.08370044052865, 163.3259911894273), 0): [(-170168.99688360593, 38132261.84792239, (224.08370044052865, 163.3259911894273), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:37:13] "POST /users HTTP/1.1" 200 -
2667.954833984375 2479.6201171875 1212.9119873046875 969.1403198242188 45910.667958036065
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:37:18] "POST /users HTTP/1.1" 200 -
2687.42041015625 2296.938232421875 1508.8970947265625 1089.0762939453125 163932.5405472517
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:37:22] "POST /users HTTP/1.1" 200 -
2823.877685546875 2640.07275390625 1211.6824951171875 937.6505126953125 50368.429796397686
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:37:26] "POST /users HTTP/1.1" 200 -
2633.77685546875 2396.37060546875 1484.52294921875 1108.5355224609375 89261.76503372192
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2391.070068359375 1838.033203125 1233.0247802734375 879.5068969726562 195508.42198495567
127.0.0.1 - - [30/Nov/2022 19:37:31] "POST /users HTTP/1.1" 200 -
[[0.15640450878778217, 273.334248483008, (323.2352941176471, 323.8897058823529), 0]]
{(0.15640450878778217, 273.334248483008, (323.2352941176471, 323.8897058823529), 0): [(0.15640450878778217, 273.334248483008, (323.2352941176471, 323.8897058823529), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2681.24267578125 2274.12744140625 1216.3741455078125 920.3847045898438 120501.81061184406
127.0.0.1 - - [30/Nov/2022 19:37:36] "POST /users HTTP/1.1" 200 -
[[-0.07878326997909182, 297.74634080321323, (263.77456647398844, 276.9653179190751), 0]]
{(-0.07878326997909182, 297.74634080321323, (263.77456647398844, 276.9653179190751), 0): [(-0.07878326997909182, 297.74634080321323, (263.77456647398844, 276.9653179190751), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:37:41] "POST /users HTTP/1.1" 200 -
2351.232421875 2078.365966796875 1324.03759765625 1016.8113403320312 83831.73974297941
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2622.6875 2446.51123046875 1298.1109619140625 999.280029296875 52646.91892904043
127.0.0.1 - - [30/Nov/2022 19:37:46] "POST /users HTTP/1.1" 200 -
[[-0.05013319830314397, 42.54839279372275, (120.83229813664596, 36.49068322981366), 0]]
{(-0.05013319830314397, 42.54839279372275, (120.83229813664596, 36.49068322981366), 0): [(-0.05013319830314397, 42.54839279372275, (120.83229813664596, 36.49068322981366), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2617.2861328125 2433.330322265625 1309.5291748046875 964.8280639648438 63409.77224095166
127.0.0.1 - - [30/Nov/2022 19:37:51] "POST /users HTTP/1.1" 200 -
[[-21803.391307353544, 2624032.061451441, (120.34810126582279, 35.31645569620253), 0]]
{(-21803.391307353544, 2624032.061451441, (120.34810126582279, 35.31645569620253), 0): [(-21803.391307353544, 2624032.061451441, (120.34810126582279, 35.31645569620253), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
3001.499267578125 2600.1728515625 1061.1761474609375 710.5357055664062 140721.27185566723
127.0.0.1 - - [30/Nov/2022 19:37:56] "POST /users HTTP/1.1" 200 -
[[-0.011588162379916082, 236.5694634050069, (271.1044776119403, 233.4278606965174), 0]]
{(-0.011588162379916082, 236.5694634050069, (271.1044776119403, 233.4278606965174), 0): [(-0.011588162379916082, 236.5694634050069, (271.1044776119403, 233.4278606965174), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2431.046630859375 2195.562744140625 1449.4329833984375 1194.861328125 59947.52283221483
127.0.0.1 - - [30/Nov/2022 19:38:01] "POST /users HTTP/1.1" 200 -
[[2.3780618014655106, -240.11502443049102, (128.71317829457365, 65.97286821705427), 0]]
{(2.3780618014655106, -240.11502443049102, (128.71317829457365, 65.97286821705427), 0): [(2.3780618014655106, -240.11502443049102, (128.71317829457365, 65.97286821705427), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2663.973876953125 2089.52587890625 1376.10595703125 1070.2161865234375 175717.76629123092
[2022-11-30 19:38:05,961] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 14, in post
    no_wires = post_processing(image,mask_im,bundle_area,bndl_width,area_threshold=0.01,erosion_dialation= False,header_blur=blur)
  File "/tmp/ipykernel_8512/3941675305.py", line 8, in post_processing
    return count_yellow_wires(change_brightness(mask_img),blur,bundle_area,bndl_width,area_threshold,erosion_dialation)
  File "/tmp/ipykernel_8512/1990652061.py", line 60, in count_yellow_wires
    line = fit_line(c)
  File "/tmp/ipykernel_8512/1990652061.py", line 30, in fit_line
    model.fit(c[:,:,0],[a[0] for a  in c[:,:,1]])
  File "/root/anaconda3/lib/python3.9/site-packages/sklearn/linear_model/_base.py", line 718, in fit
    self.coef_, self._residues, self.rank_, self.singular_ = linalg.lstsq(X, y)
  File "/root/anaconda3/lib/python3.9/site-packages/scipy/linalg/basic.py", line 1214, in lstsq
    raise ValueError('illegal value in %d-th argument of internal %s'
ValueError: illegal value in 4-th argument of internal None
127.0.0.1 - - [30/Nov/2022 19:38:05] "POST /users HTTP/1.1" 500 -
Intel MKL ERROR: Parameter 4 was incorrect on entry to DLASCL.
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2782.122314453125 2220.84912109375 1284.6820068359375 923.1455078125 202920.74532285333
127.0.0.1 - - [30/Nov/2022 19:38:10] "POST /users HTTP/1.1" 200 -
[[-0.6556555702491953, 608.9645935420381, (305.335, 408.77), 0]]
{(-0.6556555702491953, 608.9645935420381, (305.335, 408.77), 0): [(-0.6556555702491953, 608.9645935420381, (305.335, 408.77), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2648.523193359375 2042.1241455078125 1315.773193359375 914.9930419921875 243032.7021868676
127.0.0.1 - - [30/Nov/2022 19:38:15] "POST /users HTTP/1.1" 200 -
[[-0.0501798421177108, 506.53370175737365, (174.46511627906978, 497.77906976744185), 0]]
{(-0.0501798421177108, 506.53370175737365, (174.46511627906978, 497.77906976744185), 0): [(-0.0501798421177108, 506.53370175737365, (174.46511627906978, 497.77906976744185), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:38:20,219] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 14, in post
    no_wires = post_processing(image,mask_im,bundle_area,bndl_width,area_threshold=0.01,erosion_dialation= False,header_blur=blur)
  File "/tmp/ipykernel_8512/3941675305.py", line 8, in post_processing
    return count_yellow_wires(change_brightness(mask_img),blur,bundle_area,bndl_width,area_threshold,erosion_dialation)
  File "/tmp/ipykernel_8512/1990652061.py", line 60, in count_yellow_wires
    line = fit_line(c)
  File "/tmp/ipykernel_8512/1990652061.py", line 30, in fit_line
    model.fit(c[:,:,0],[a[0] for a  in c[:,:,1]])
  File "/root/anaconda3/lib/python3.9/site-packages/sklearn/linear_model/_base.py", line 718, in fit
    self.coef_, self._residues, self.rank_, self.singular_ = linalg.lstsq(X, y)
  File "/root/anaconda3/lib/python3.9/site-packages/scipy/linalg/basic.py", line 1214, in lstsq
    raise ValueError('illegal value in %d-th argument of internal %s'
ValueError: illegal value in 4-th argument of internal None
127.0.0.1 - - [30/Nov/2022 19:38:20] "POST /users HTTP/1.1" 500 -
2341.00634765625 2038.2801513671875 1268.947998046875 886.5877685546875 115750.45788638294

Intel MKL ERROR: Parameter 4 was incorrect on entry to DLASCL.
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2705.93310546875 2358.3076171875 1349.912841796875 1039.3662109375 107953.92418658733
127.0.0.1 - - [30/Nov/2022 19:38:25] "POST /users HTTP/1.1" 200 -
[[-0.004993018334968214, 310.36880748307897, (220.59358288770053, 309.26737967914437), 0]]
{(-0.004993018334968214, 310.36880748307897, (220.59358288770053, 309.26737967914437), 0): [(-0.004993018334968214, 310.36880748307897, (220.59358288770053, 309.26737967914437), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2372.2763671875 2097.400146484375 1263.09375 793.1793212890625 129168.30221793056
127.0.0.1 - - [30/Nov/2022 19:38:30] "POST /users HTTP/1.1" 200 -
[[-0.02580676806772174, 186.37071972388262, (188.67434210526315, 181.5016447368421), 0]]
{(-0.02580676806772174, 186.37071972388262, (188.67434210526315, 181.5016447368421), 0): [(-0.02580676806772174, 186.37071972388262, (188.67434210526315, 181.5016447368421), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2493.610107421875 2260.614013671875 1418.8480224609375 1164.6781005859375 59220.598945617676
127.0.0.1 - - [30/Nov/2022 19:38:35] "POST /users HTTP/1.1" 200 -
[[-0.003765903650238136, 178.12383126269572, (128.62131519274377, 177.63945578231292), 0]]
{(-0.003765903650238136, 178.12383126269572, (128.62131519274377, 177.63945578231292), 0): [(-0.003765903650238136, 178.12383126269572, (128.62131519274377, 177.63945578231292), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2474.32421875 2274.84619140625 1376.0081787109375 1129.1983642578125 49233.13491618633
127.0.0.1 - - [30/Nov/2022 19:38:40] "POST /users HTTP/1.1" 200 -
[[-0.0026708379177278227, 142.22335775520688, (142.8469387755102, 141.84183673469389), 1]]
{(-0.0026708379177278227, 142.22335775520688, (142.8469387755102, 141.84183673469389), 1): [(-0.0026708379177278227, 142.22335775520688, (142.8469387755102, 141.84183673469389), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2473.098388671875 2218.020263671875 1191.8192138671875 880.778076171875 79339.79020118713
127.0.0.1 - - [30/Nov/2022 19:38:45] "POST /users HTTP/1.1" 200 -
[[-14724.60495521409, 1354778.444088492, (91.99465240641712, 193.52941176470588), 1], [-0.0246559419786285, 117.94202780502984, (222.37414965986395, 112.45918367346938), 1]]
{(-14724.60495521409, 1354778.444088492, (91.99465240641712, 193.52941176470588), 1): [(-14724.60495521409, 1354778.444088492, (91.99465240641712, 193.52941176470588), 1)], (-0.0246559419786285, 117.94202780502984, (222.37414965986395, 112.45918367346938), 1): [(-0.0246559419786285, 117.94202780502984, (222.37414965986395, 112.45918367346938), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2631.263916015625 2451.6787109375 1428.9779052734375 1129.51953125 53778.293511360884
127.0.0.1 - - [30/Nov/2022 19:38:50] "POST /users HTTP/1.1" 200 -
[[-244888.09403673053, 35400193.17011574, (144.55612244897958, 119.86224489795919), 0]]
{(-244888.09403673053, 35400193.17011574, (144.55612244897958, 119.86224489795919), 0): [(-244888.09403673053, 35400193.17011574, (144.55612244897958, 119.86224489795919), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2275.244384765625 1992.246337890625 1207.7330322265625 902.4632568359375 86390.75020551682
127.0.0.1 - - [30/Nov/2022 19:38:55] "POST /users HTTP/1.1" 200 -
[[-0.020215277097301854, 200.14306599521245, (170.32, 196.7), 0]]
{(-0.020215277097301854, 200.14306599521245, (170.32, 196.7), 0): [(-0.020215277097301854, 200.14306599521245, (170.32, 196.7), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2424.845947265625 2214.219970703125 1102.6153564453125 916.7769775390625 39142.39003992081
127.0.0.1 - - [30/Nov/2022 19:39:00] "POST /users HTTP/1.1" 200 -
[[-0.07200412852219598, 166.05086792162177, (118.91054313099042, 157.4888178913738), 0]]
{(-0.07200412852219598, 166.05086792162177, (118.91054313099042, 157.4888178913738), 0): [(-0.07200412852219598, 166.05086792162177, (118.91054313099042, 157.4888178913738), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:39:04] "POST /users HTTP/1.1" 200 -
2872.751953125 2670.37939453125 1582.892333984375 1279.7999267578125 61337.585940778255
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2604.03369140625 2325.94140625 1460.35595703125 1179.2608642578125 78170.37669557333
127.0.0.1 - - [30/Nov/2022 19:39:09] "POST /users HTTP/1.1" 200 -
[[-67033.5294955928, 8079199.819575451, (120.5220588235294, 180.83455882352942), 0]]
{(-67033.5294955928, 8079199.819575451, (120.5220588235294, 180.83455882352942), 0): [(-67033.5294955928, 8079199.819575451, (120.5220588235294, 180.83455882352942), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2944.638671875 2729.834716796875 1315.91357421875 1104.005126953125 45518.77258712053
127.0.0.1 - - [30/Nov/2022 19:39:15] "POST /users HTTP/1.1" 200 -
[[-0.02529606261991762, 75.07746479011773, (165.0, 70.90361445783132), 0]]
{(-0.02529606261991762, 75.07746479011773, (165.0, 70.90361445783132), 0): [(-0.02529606261991762, 75.07746479011773, (165.0, 70.90361445783132), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2382.386962890625 2151.228271484375 1649.08447265625 1358.546142578125 67160.4601842165
127.0.0.1 - - [30/Nov/2022 19:39:20] "POST /users HTTP/1.1" 200 -
[[-9790.12400516877, 564863.6632511783, (57.68456375838926, 124.63087248322148), 0]]
{(-9790.12400516877, 564863.6632511783, (57.68456375838926, 124.63087248322148), 0): [(-9790.12400516877, 564863.6632511783, (57.68456375838926, 124.63087248322148), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
127.0.0.1 - - [30/Nov/2022 19:39:24] "POST /users HTTP/1.1" 200 -
2244.7958984375 1904.2869873046875 1630.3389892578125 1314.05810546875 107696.45935113728
[]
{}
0
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
3143.0419921875 2924.574462890625 1625.30126953125 1299.1551513671875 71252.33662506938
127.0.0.1 - - [30/Nov/2022 19:39:29] "POST /users HTTP/1.1" 200 -
[[-0.012783884254124541, 101.8929302662079, (146.56730769230768, 100.01923076923077), 0]]
{(-0.012783884254124541, 101.8929302662079, (146.56730769230768, 100.01923076923077), 0): [(-0.012783884254124541, 101.8929302662079, (146.56730769230768, 100.01923076923077), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2719.62548828125 1948.4102783203125 1353.754150390625 924.1215209960938 331339.21848457307
127.0.0.1 - - [30/Nov/2022 19:39:34] "POST /users HTTP/1.1" 200 -
[[-0.01209116581762066, 519.1206319910143, (271.52048558421853, 515.8376327769347), 0]]
{(-0.01209116581762066, 519.1206319910143, (271.52048558421853, 515.8376327769347), 0): [(-0.01209116581762066, 519.1206319910143, (271.52048558421853, 515.8376327769347), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2041.892822265625 1610.774658203125 1093.049560546875 728.6292114257812 157108.23186010122
127.0.0.1 - - [30/Nov/2022 19:39:39] "POST /users HTTP/1.1" 200 -
[[-0.013676236584899342, 264.674789369413, (228.73291925465838, 261.54658385093165), 0]]
{(-0.013676236584899342, 264.674789369413, (228.73291925465838, 261.54658385093165), 0): [(-0.013676236584899342, 264.674789369413, (228.73291925465838, 261.54658385093165), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
[2022-11-30 19:39:43,912] ERROR in app: Exception on /users [POST]
Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/anaconda3/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/root/anaconda3/lib/python3.9/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/tmp/ipykernel_8512/80991225.py", line 14, in post
    no_wires = post_processing(image,mask_im,bundle_area,bndl_width,area_threshold=0.01,erosion_dialation= False,header_blur=blur)
  File "/tmp/ipykernel_8512/3941675305.py", line 10, in post_processing
    return count_yellow_wires(mask_img,blur,bundle_area,bndl_width,area_threshold,erosion_dialation)
  File "/tmp/ipykernel_8512/1990652061.py", line 60, in count_yellow_wires
    line = fit_line(c)
  File "/tmp/ipykernel_8512/1990652061.py", line 30, in fit_line
    model.fit(c[:,:,0],[a[0] for a  in c[:,:,1]])
  File "/root/anaconda3/lib/python3.9/site-packages/sklearn/linear_model/_base.py", line 718, in fit
    self.coef_, self._residues, self.rank_, self.singular_ = linalg.lstsq(X, y)
  File "/root/anaconda3/lib/python3.9/site-packages/scipy/linalg/basic.py", line 1214, in lstsq
    raise ValueError('illegal value in %d-th argument of internal %s'
ValueError: illegal value in 4-th argument of internal None
127.0.0.1 - - [30/Nov/2022 19:39:43] "POST /users HTTP/1.1" 500 -
2874.99560546875 2479.96875 1502.2615966796875 1277.3492431640625 88846.4197653532

Intel MKL ERROR: Parameter 4 was incorrect on entry to DLASCL.
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2876.745849609375 2392.28662109375 1484.6527099609375 1052.6939697265625 209266.39804452658
127.0.0.1 - - [30/Nov/2022 19:39:49] "POST /users HTTP/1.1" 200 -
[[-0.09828067701963634, 352.5232155960145, (180.92911877394636, 334.7413793103448), 1], [-0.020773422085144145, 58.94162662161386, (352.57142857142856, 51.617511520737324), 1]]
{(-0.09828067701963634, 352.5232155960145, (180.92911877394636, 334.7413793103448), 1): [(-0.09828067701963634, 352.5232155960145, (180.92911877394636, 334.7413793103448), 1)], (-0.020773422085144145, 58.94162662161386, (352.57142857142856, 51.617511520737324), 1): [(-0.020773422085144145, 58.94162662161386, (352.57142857142856, 51.617511520737324), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2858.582275390625 2598.24365234375 1442.574951171875 1095.3963623046875 90383.99577704072
[[193155.7073862345, -29079336.978400007, (150.54947916666666, 154.16666666666666), 1]]
{(193155.7073862345, -29079336.978400007, (150.54947916666666, 154.16666666666666), 1): [(193155.7073862345, -29079336.978400007, (150.54947916666666, 154.16666666666666), 1)]}
127.0.0.1 - - [30/Nov/2022 19:39:54] "POST /users HTTP/1.1" 200 -
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2406.93505859375 1935.397705078125 1509.90380859375 1091.3013916015625 197386.6758837402
127.0.0.1 - - [30/Nov/2022 19:39:59] "POST /users HTTP/1.1" 200 -
[[-0.1032343230085557, 360.8264192266839, (140.93870402802102, 346.27670753064797), 1]]
{(-0.1032343230085557, 360.8264192266839, (140.93870402802102, 346.27670753064797), 1): [(-0.1032343230085557, 360.8264192266839, (140.93870402802102, 346.27670753064797), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2841.92529296875 2419.263916015625 1378.21142578125 1020.43017578125 151220.31577301025
127.0.0.1 - - [30/Nov/2022 19:40:04] "POST /users HTTP/1.1" 200 -
[[-0.018875706663668463, 241.31998684118682, (183.7693194925029, 237.85121107266437), 1]]
{(-0.018875706663668463, 241.31998684118682, (183.7693194925029, 237.85121107266437), 1): [(-0.018875706663668463, 241.31998684118682, (183.7693194925029, 237.85121107266437), 1)]}
2
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2675.650390625 2368.70361328125 1491.984130859375 1216.5751953125 84535.88521778584
127.0.0.1 - - [30/Nov/2022 19:40:09] "POST /users HTTP/1.1" 200 -
[[-0.03386814345129654, 181.463997632083, (188.72972972972974, 175.07207207207207), 0]]
{(-0.03386814345129654, 181.463997632083, (188.72972972972974, 175.07207207207207), 0): [(-0.03386814345129654, 181.463997632083, (188.72972972972974, 175.07207207207207), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2749.37158203125 2542.0341796875 1628.223876953125 1316.355712890625 64661.9350104332
127.0.0.1 - - [30/Nov/2022 19:40:14] "POST /users HTTP/1.1" 200 -
[[-0.09743123432871846, 90.08172678178995, (84.7926267281106, 81.82027649769586), 0]]
{(-0.09743123432871846, 90.08172678178995, (84.7926267281106, 81.82027649769586), 0): [(-0.09743123432871846, 90.08172678178995, (84.7926267281106, 81.82027649769586), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2706.835693359375 2468.956787109375 1391.6082763671875 1085.7987060546875 72745.64610671997
127.0.0.1 - - [30/Nov/2022 19:40:19] "POST /users HTTP/1.1" 200 -
[[-0.013354429607699813, 157.2652023762883, (99.3913043478261, 155.93788819875778), 0]]
{(-0.013354429607699813, 157.2652023762883, (99.3913043478261, 155.93788819875778), 0): [(-0.013354429607699813, 157.2652023762883, (99.3913043478261, 155.93788819875778), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2317.114501953125 1987.3392333984375 889.9341430664062 572.52783203125 104672.75146257132
127.0.0.1 - - [30/Nov/2022 19:40:23] "POST /users HTTP/1.1" 200 -
[[-0.02702852304891838, 243.67569370533195, (196.39795918367346, 238.3673469387755), 0]]
{(-0.02702852304891838, 243.67569370533195, (196.39795918367346, 238.3673469387755), 0): [(-0.02702852304891838, 243.67569370533195, (196.39795918367346, 238.3673469387755), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2770.40966796875 2374.997802734375 1489.712890625 1156.051513671875 131933.66741770506
127.0.0.1 - - [30/Nov/2022 19:40:28] "POST /users HTTP/1.1" 200 -
[[-0.007298836480979903, 281.2113989223062, (135.42640692640694, 280.22294372294374), 0]]
{(-0.007298836480979903, 281.2113989223062, (135.42640692640694, 280.22294372294374), 0): [(-0.007298836480979903, 281.2113989223062, (135.42640692640694, 280.22294372294374), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2652.836669921875 2385.685302734375 1198.6571044921875 876.0921020507812 86173.68140906096
127.0.0.1 - - [30/Nov/2022 19:40:33] "POST /users HTTP/1.1" 200 -
[[-0.003858344760124551, 159.67932694395768, (153.1627906976744, 159.08837209302325), 0]]
{(-0.003858344760124551, 159.67932694395768, (153.1627906976744, 159.08837209302325), 0): [(-0.003858344760124551, 159.67932694395768, (153.1627906976744, 159.08837209302325), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2719.249755859375 2336.825439453125 1563.9476318359375 1258.90625 116655.24192422628
127.0.0.1 - - [30/Nov/2022 19:40:38] "POST /users HTTP/1.1" 200 -
[[-193833.40451460486, 25500702.778999314, (131.55844155844156, 282.15909090909093), 0]]
{(-193833.40451460486, 25500702.778999314, (131.55844155844156, 282.15909090909093), 0): [(-193833.40451460486, 25500702.778999314, (131.55844155844156, 282.15909090909093), 0)]}
1
/tmp/ipykernel_8512/80991225.py:9: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  nparr = np.fromstring(r.data, np.uint8)
2203.122802734375 1956.39892578125 1252.83642578125 1058.71923828125 47893.345083236694
127.0.0.1 - - [30/Nov/2022 19:40:43] "POST /users HTTP/1.1" 200 -
[[-0.003919267820174368, 189.87781336295527, (97.15384615384616, 189.49704142011834), 0]]
{(-0.003919267820174368, 189.87781336295527, (97.15384615384616, 189.49704142011834), 0): [(-0.003919267820174368, 189.87781336295527, (97.15384615384616, 189.49704142011834), 0)]}
1
In [ ]:
 
In [ ]:
 
In [ ]: